home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / sun / volume1 / ethertools-3.x / part01 next >
Encoding:
Internet Message Format  |  1989-06-21  |  61.0 KB

  1. Path: uunet!cs.utexas.edu!rutgers!aramis.rutgers.edu!dartagnan.rutgers.edu!mcgrew
  2. From: mcgrew@dartagnan.rutgers.edu (Charles Mcgrew)
  3. Newsgroups: comp.sources.sun
  4. Subject: v01i036:  Ethernet tools for SunOS 3.X, Part01/02
  5. Message-ID: <Jun.21.13.53.14.1989.29064@dartagnan.rutgers.edu>
  6. Date: 21 Jun 89 17:53:17 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 2236
  9. Approved: mcgrew@aramis.rutgers.edu
  10.  
  11. Submitted-by: budd@bu-it.bu.edu
  12. Posting-number: Volume 1, Issue 36
  13. Archive-name: ethertools-3.X/part01
  14.  
  15. Please note: this will not compile under OS 4.0.X.  As Phil put it,
  16. "4.0 SNIT is a different beast altogether!".
  17.  
  18. Charles
  19.  
  20. #! /bin/sh
  21. # This is a shell archive.  Remove anything before this line, then unpack
  22. # it by saving it into a file and typing "sh file".  To overwrite existing
  23. # files, type "sh file -c".  You can also feed this as standard input via
  24. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  25. # will see the following message at the end:
  26. #        "End of archive 1 (of 2)."
  27. # Contents:  COPYRIGHT MANIFEST Makefile README addrs.c ctp.h ctpd.c
  28. #   dump.c ether-prot.h hetoea.c htoea.c iptoea.c mfgr.h mfgrs.c ns.c
  29. #   pbytes.c petaddr.c petaddrm.c petmf.c pipaddr.c protocol.h
  30. #   puthex.c samecount.c show.c tab.c terpri.c test-htoea.c xval.c
  31. # Wrapped by budd@buita on Sat Aug 13 01:14:38 1988
  32. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  33. if test -f COPYRIGHT -a "${1}" != "-c" ; then 
  34.   echo shar: Will not over-write existing file \"COPYRIGHT\"
  35. else
  36. echo shar: Extracting \"COPYRIGHT\" \(500 characters\)
  37. sed "s/^X//" >COPYRIGHT <<'END_OF_COPYRIGHT'
  38. X/*
  39. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  40. X * All Rights Reserved
  41. X *
  42. X * Permission is granted to any individual or institution to use, copy,
  43. X * or redistribute this software so long as it is not sold for profit,
  44. X * provided that this notice and the original copyright notices are
  45. X * retained.  Boston University makes no representations about the
  46. X * suitability of this software for any purpose.  It is provided "as is"
  47. X * without express or implied warranty.
  48. X */
  49. END_OF_COPYRIGHT
  50. if test 500 -ne `wc -c <COPYRIGHT`; then
  51.     echo shar: \"COPYRIGHT\" unpacked with wrong size!
  52. fi
  53. # end of overwriting check
  54. fi
  55. if test -f MANIFEST -a "${1}" != "-c" ; then 
  56.   echo shar: Will not over-write existing file \"MANIFEST\"
  57. else
  58. echo shar: Extracting \"MANIFEST\" \(1104 characters\)
  59. sed "s/^X//" >MANIFEST <<'END_OF_MANIFEST'
  60. X   File Name        Archive #    Description
  61. X-----------------------------------------------------------
  62. X COPYRIGHT                 1    
  63. X MANIFEST                  1    This shipping list
  64. X Makefile                  1    
  65. X README                    1    
  66. X addrs.c                   1    
  67. X ctp.c                     2    
  68. X ctp.h                     1    
  69. X ctpd.c                    1    
  70. X dump.c                    1    
  71. X ether-prot.h              1    
  72. X hetoea.c                  1    
  73. X htoea.c                   1    
  74. X if_ctp.c                  2    
  75. X iptoea.c                  1    
  76. X mfgr.h                    1    
  77. X mfgrs.c                   1    
  78. X nit.c                     2    
  79. X ns.c                      1    
  80. X packet.h                  2    
  81. X pbytes.c                  1    
  82. X petaddr.c                 1    
  83. X petaddrm.c                1    
  84. X petmf.c                   1    
  85. X pipaddr.c                 1    
  86. X protocol.h                1    
  87. X puthex.c                  1    
  88. X rlog.c                    2    
  89. X samecount.c               1    
  90. X show.c                    1    
  91. X tab.c                     1    
  92. X terpri.c                  1    
  93. X test-htoea.c              1    
  94. X xval.c                    1    
  95. END_OF_MANIFEST
  96. if test 1104 -ne `wc -c <MANIFEST`; then
  97.     echo shar: \"MANIFEST\" unpacked with wrong size!
  98. fi
  99. # end of overwriting check
  100. fi
  101. if test -f Makefile -a "${1}" != "-c" ; then 
  102.   echo shar: Will not over-write existing file \"Makefile\"
  103. else
  104. echo shar: Extracting \"Makefile\" \(2770 characters\)
  105. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  106. X# Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  107. X# All Rights Reserved
  108. X
  109. X# Permission is granted to any individual or institution to use, copy,
  110. X# or redistribute this software so long as it is not sold for profit,
  111. X# provided that this notice and the original copyright notices are
  112. X# retained.  Boston University makes no representations about the
  113. X# suitability of this software for any purpose.  It is provided "as is"
  114. X# without express or implied warranty.
  115. X
  116. XCFLAGS=-g
  117. X
  118. XALL=ctp show ctpd htoea dump rlog tab addrs samecount
  119. Xall:    $(ALL)
  120. X
  121. X# if_ctp.c is a kernel level CTP server
  122. X
  123. XLIB=lib.a
  124. XLIBFILES=ns.o mfgrs.o terpri.o pipaddr.o xval.o htoea.o hetoea.o iptoea.o \
  125. X    nit.o puthex.o pbytes.o petaddr.o petmf.o petaddrm.o
  126. X
  127. X$(LIB):    $(LIBFILES)
  128. X    ar r $(LIB) $(LIBFILES)
  129. X    ranlib lib.a
  130. X
  131. X# ctp client (like ping)
  132. XCTP=ctp.o $(LIB)
  133. Xctp:    $(CTP)
  134. X    $(CC) $(CFLAGS) -o ctp $(CTP)
  135. X
  136. X# user mode ctp server
  137. XCTPD=ctpd.o $(LIB)
  138. Xctpd:    $(CTPD)
  139. X    $(CC) $(CFLAGS) -o ctpd $(CTPD)
  140. X
  141. X# watch CTP traffic
  142. XSHOW=show.o $(LIB)
  143. Xshow:    $(SHOW)
  144. X    $(CC) $(CFLAGS) -o show $(SHOW)
  145. X
  146. X# dump traffic
  147. XDUMP=dump.o $(LIB)
  148. Xdump:    $(DUMP)
  149. X    $(CC) $(CFLAGS) -o dump $(DUMP)
  150. X
  151. X# convert hosts to ether addresses (test for my library routine)
  152. XHTOEA=test-htoea.o lib.a
  153. Xhtoea:    $(HTOEA)
  154. X    $(CC) $(CFLAGS) -o htoea $(HTOEA)
  155. X
  156. X################################################################
  157. X
  158. X# read log -- a packet printer
  159. XRLOG=rlog.o $(LIB)
  160. Xrlog:    $(RLOG)
  161. X    $(CC) $(CFLAGS) -o rlog $(RLOG)
  162. X
  163. X# tabulate information
  164. XTAB=tab.o $(LIB)
  165. Xtab:    $(TAB)
  166. X    $(CC) $(CFLAGS) -o tab $(TAB)
  167. X
  168. X# read log, print address pairs
  169. XADDRS=addrs.o $(LIB)
  170. Xaddrs:    $(ADDRS)
  171. X    $(CC) $(CFLAGS) -o addrs $(ADDRS)
  172. X
  173. X# count identical lines (ie; dump | addrs | sort | samecount)
  174. Xsamecount: samecount.c
  175. X    $(CC) $(CFLAGS) -o samecount samecount.c
  176. X
  177. Xclean:
  178. X    rm -f *.o $(ALL) ether.h core *~ \#*
  179. X
  180. Xshar:
  181. X    shar README COPYRIGHT Makefile *.c *.h > shar
  182. X
  183. Xkit:
  184. X    makekit -oMANIFEST README COPYRIGHT Makefile *.c *.h
  185. X
  186. Xdepend:
  187. X    grep '^#[     ]*include' *.c | grep -v '<' | \
  188. X    sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' \
  189. X        -e 's/\.c/.o/' \
  190. X        -e 's,../[a-zA-Z]*/,,' | \
  191. X    awk ' { if ($$1 != prev) { print rec; rec = $$0; prev = $$1; } \
  192. X        else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
  193. X               else rec = rec " " $$2 } } \
  194. X          END { print rec } ' > makedep
  195. X    echo '$$r makedep' >>eddep
  196. X    echo '/^# DO NOT DELETE THIS LINE/+1,$$d' >eddep
  197. X    echo '$$r makedep' >>eddep
  198. X    echo 'w' >>eddep
  199. X    cp Makefile Makefile.bak
  200. X    ed - Makefile < eddep
  201. X    rm eddep makedep
  202. X
  203. X# DO NOT DELETE THIS LINE
  204. X
  205. Xaddrs.o: packet.h
  206. Xctp.o: ctp.h
  207. Xctpd.o: ctp.h
  208. Xif_ctp.o: ether.h param.h systm.h mbuf.h socket.h time.h kernel.h errno.h
  209. Xif_ctp.o: ioctl.h if.h in.h if_ether.h
  210. Xmfgrs.o: mfgr.h
  211. Xpetmf.o: mfgr.h
  212. Xpipaddr.o: packet.h
  213. Xrlog.o: packet.h protocol.h
  214. Xshow.o: ctp.h
  215. Xtab.o: packet.h
  216. END_OF_Makefile
  217. if test 2770 -ne `wc -c <Makefile`; then
  218.     echo shar: \"Makefile\" unpacked with wrong size!
  219. fi
  220. # end of overwriting check
  221. fi
  222. if test -f README -a "${1}" != "-c" ; then 
  223.   echo shar: Will not over-write existing file \"README\"
  224. else
  225. echo shar: Extracting \"README\" \(1407 characters\)
  226. sed "s/^X//" >README <<'END_OF_README'
  227. XCopyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  228. XAll Rights Reserved
  229. X
  230. XPermission is granted to any individual or institution to use, copy,
  231. Xor redistribute this software so long as it is not sold for profit,
  232. Xprovided that this notice and the original copyright notices are
  233. Xretained.  Boston University makes no representations about the
  234. Xsuitability of this software for any purpose.  It is provided "as is"
  235. Xwithout express or implied warranty.
  236. X
  237. X****************************************************************
  238. X
  239. XThis is a set of tools for access to raw ethernet on Suns.  The only
  240. XSun dependant file is nit.c which contains the actual code to call NIT
  241. Xon Sun 3.x systems.
  242. X
  243. Xctp
  244. X    Is a CTP client.  It sends Ethernet Version 2 Configuration
  245. X    Test protocol packets.  Multiple hosts/addresses will send out
  246. X    a packet to be forwarded thru that path.  The last entry in
  247. X    the packet is a 'reply' back to us.
  248. X
  249. X    Has many options and a usage message.
  250. X
  251. X
  252. Xctpd
  253. X    Is a user mode CTP daemon.
  254. X
  255. Xif_ctpd.c
  256. X    Is a kernel mode CTP daemon.
  257. X
  258. Xshow
  259. X    Watches all CTP traffic.
  260. X
  261. Xhtoea
  262. X    Converts hosts to ether addresses.
  263. X
  264. Xdump
  265. X    Dumps ether traffic (no filtering)
  266. X
  267. Xrlog
  268. X    Reads and interprets a log written by dump
  269. X
  270. Xtab
  271. X    Tablate sources, dests, protocols, lengths from a log.
  272. X
  273. Xaddrs
  274. X    Print address pairs, proto, len etc.
  275. X
  276. Xsamecount
  277. X    For use as:
  278. X
  279. X    dump -c nnn | addrs | sort | samecount
  280. X
  281. X    to get address pair counts.
  282. X
  283. END_OF_README
  284. if test 1407 -ne `wc -c <README`; then
  285.     echo shar: \"README\" unpacked with wrong size!
  286. fi
  287. # end of overwriting check
  288. fi
  289. if test -f addrs.c -a "${1}" != "-c" ; then 
  290.   echo shar: Will not over-write existing file \"addrs.c\"
  291. else
  292. echo shar: Extracting \"addrs.c\" \(2218 characters\)
  293. sed "s/^X//" >addrs.c <<'END_OF_addrs.c'
  294. X/*
  295. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  296. X * All Rights Reserved
  297. X *
  298. X * Permission is granted to any individual or institution to use, copy,
  299. X * or redistribute this software so long as it is not sold for profit,
  300. X * provided that this notice and the original copyright notices are
  301. X * retained.  Boston University makes no representations about the
  302. X * suitability of this software for any purpose.  It is provided "as is"
  303. X * without express or implied warranty.
  304. X */
  305. X# include <stdio.h>
  306. X# include <ctype.h>
  307. X# include "packet.h"
  308. X
  309. Xstruct hent {
  310. X    union {
  311. X    EA hd_ea;
  312. X    short hd_type;
  313. X    } h_data;
  314. X    int h_cnt;
  315. X    int h_inuse;
  316. X};
  317. X# define h_ea h_data.hd_ea
  318. X# define h_type h_data.hd_type
  319. X
  320. Xint length[ 1520 ];
  321. X
  322. Xint count = 0;
  323. Xint pc;
  324. Xint sflg, dflg, pflg;
  325. X
  326. Xmain(argc, argv)
  327. X    int argc;
  328. X    char *argv[];
  329. X{
  330. X    extern char *optarg;
  331. X    extern int optind, opterr;
  332. X    int errs, c;
  333. X    char line[ 4096 ];
  334. X    register byte *pp;
  335. X    register char *lp;
  336. X    register int i;
  337. X
  338. X    errs = 0;
  339. X    sflg = dflg = pflg = 0;
  340. X    while( (c = getopt( argc, argv, "sdp" )) != EOF ) {
  341. X    switch( c ) {
  342. X    case 's':
  343. X        sflg++;
  344. X        break;
  345. X    case 'd':
  346. X        dflg++;
  347. X        break;
  348. X    case 'p':
  349. X        pflg++;
  350. X        break;
  351. X    default:
  352. X        errs++;
  353. X    }
  354. X    }
  355. X    if( errs > 0 )
  356. X    exit( 1 );
  357. X
  358. X    if( sflg + dflg + pflg == 0 )
  359. X    sflg = dflg = pflg = 1;
  360. X
  361. X    pc = 0;
  362. X    pp = packet.p_bytes;
  363. X    while( gets( line ) ) {
  364. X    if( line[0] == ' ' || line[0] == '*' || line[0] == '\0' ) {
  365. X        if( pc > 0 )
  366. X        process();
  367. X        pp = packet.p_bytes;
  368. X        pc = 0;
  369. X        continue;
  370. X    }
  371. X
  372. X    for( lp = line; *lp; lp++ ) {
  373. X        if( isspace( *lp ) )
  374. X        continue;
  375. X        else if( isxdigit( *lp ) && isxdigit( lp[1] ) ) {
  376. X        *pp++ = xval( *lp, lp[1] );
  377. X        lp++;
  378. X        pc++;
  379. X        }
  380. X        else
  381. X        fprintf( stderr, "you lose: %s\n", lp );
  382. X    }
  383. X    }
  384. X    if( pc > 0 )
  385. X    process();
  386. X}
  387. X
  388. Xprocess() {
  389. X    register struct etherpacket *e = (struct etherpacket *) &packet;
  390. X    u_short type;
  391. X
  392. X    count++;
  393. X    type = packet.p_ether.e_type;
  394. X    if( sflg ) {
  395. X    petaddr( e->e_src );
  396. X    putchar(' ');
  397. X    }
  398. X    if( dflg ) {
  399. X    petaddr( e->e_dst );
  400. X    putchar(' ');
  401. X    }
  402. X    if( pflg ) {
  403. X    puthex( (type >> 8) & 0xff );
  404. X    putchar( '-' );
  405. X    puthex( type & 255 );
  406. X    }
  407. X    /* pc == len */
  408. X}
  409. END_OF_addrs.c
  410. if test 2218 -ne `wc -c <addrs.c`; then
  411.     echo shar: \"addrs.c\" unpacked with wrong size!
  412. fi
  413. # end of overwriting check
  414. fi
  415. if test -f ctp.h -a "${1}" != "-c" ; then 
  416.   echo shar: Will not over-write existing file \"ctp.h\"
  417. else
  418. echo shar: Extracting \"ctp.h\" \(1268 characters\)
  419. sed "s/^X//" >ctp.h <<'END_OF_ctp.h'
  420. X/*
  421. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  422. X * All Rights Reserved
  423. X *
  424. X * Permission is granted to any individual or institution to use, copy,
  425. X * or redistribute this software so long as it is not sold for profit,
  426. X * provided that this notice and the original copyright notices are
  427. X * retained.  Boston University makes no representations about the
  428. X * suitability of this software for any purpose.  It is provided "as is"
  429. X * without express or implied warranty.
  430. X */
  431. X/*
  432. X *    Parameters for Ethernet Version 2
  433. X *    Configuration Test Protocol
  434. X *
  435. X *    Philip Budne @ BU/DSG
  436. X */
  437. X
  438. X# define ETHERTYPE_CTP 0x9000
  439. X
  440. X# define etcmp(a,b) (((*( (u_long *)a ))  == (*((u_long *)b))) && \
  441. X             ((*( (u_short *)&a[4] )) == (*((u_short *)&b[4]))))
  442. X
  443. Xstatic u_char bcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };    /* broadcast */
  444. Xstatic u_char mcast[] = { 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00 };    /* CTP mcast */
  445. X
  446. X# define CTP_REP 1
  447. X# define CTP_FWD 2
  448. X
  449. X# if defined(vax) || defined(ns32000)
  450. X# define CTP_SHORT(sp) (*(u_short *)(sp))
  451. X# define SSWAP(s) (s)
  452. X# else /* not defined(vax) || defined(ns32000) */
  453. X# define CTP_SHORT(sp) (*sp | (sp[1]<<8))
  454. X# define SSWAP(s) ((((s)>>8) & 0xff) | (((s)<<8) & 0xff00))
  455. X# endif /* not defined(vax) || defined(ns32000) */
  456. END_OF_ctp.h
  457. if test 1268 -ne `wc -c <ctp.h`; then
  458.     echo shar: \"ctp.h\" unpacked with wrong size!
  459. fi
  460. # end of overwriting check
  461. fi
  462. if test -f ctpd.c -a "${1}" != "-c" ; then 
  463.   echo shar: Will not over-write existing file \"ctpd.c\"
  464. else
  465. echo shar: Extracting \"ctpd.c\" \(3465 characters\)
  466. sed "s/^X//" >ctpd.c <<'END_OF_ctpd.c'
  467. X/*
  468. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  469. X * All Rights Reserved
  470. X *
  471. X * Permission is granted to any individual or institution to use, copy,
  472. X * or redistribute this software so long as it is not sold for profit,
  473. X * provided that this notice and the original copyright notices are
  474. X * retained.  Boston University makes no representations about the
  475. X * suitability of this software for any purpose.  It is provided "as is"
  476. X * without express or implied warranty.
  477. X */
  478. X# include <sys/ioctl.h>            /* TIOCNOTTY */
  479. X# include <sys/types.h>
  480. X# include <sys/time.h>
  481. X# include <net/nit.h>
  482. X# include <stdio.h>
  483. X# include "ctp.h"
  484. X
  485. Xstruct packet {
  486. X    u_char  p_dst[ 6 ];
  487. X    u_char  p_src[ 6 ];
  488. X    u_short p_type;
  489. X    u_char  p_data[ 2048 ];
  490. X};
  491. X
  492. Xu_char localaddr[ 6 ];
  493. Xint debug = 0;
  494. Xchar *interface = "ie0";
  495. X
  496. Xmain(argc, argv)
  497. X    int argc;
  498. X    char *argv[];
  499. X{
  500. X    extern char *optarg;
  501. X    extern int optind, opterr;
  502. X    int s, c, errs;
  503. X    void nit_input();            /* forward */
  504. X
  505. X    errs = 0;
  506. X    while( (c = getopt( argc, argv, "di:" )) != EOF ) {
  507. X    switch( c ) {
  508. X    case 'd':
  509. X        debug++;
  510. X        break;
  511. X    case 'i':
  512. X        interface = optarg;
  513. X        break;
  514. X    default:
  515. X        errs++;
  516. X    }
  517. X    }
  518. X    if( errs > 0 )
  519. X    exit( 1 );
  520. X
  521. X    s = nit_open( interface, ETHERTYPE_CTP, localaddr, 1 );
  522. X    if( s < 0 )
  523. X    exit( 1 );
  524. X
  525. X    printf("%s address ", interface );
  526. X    petaddr( localaddr );
  527. X    puts( "" );
  528. X    if( !debug ) {
  529. X    int i;
  530. X
  531. X    i = fork();
  532. X    if( i < 0 ) {
  533. X        perror( "fork" );
  534. X        exit( 1 );
  535. X    }
  536. X    else if( i != 0 )
  537. X        exit( 0 );
  538. X
  539. X    for( i = getdtablesize() - 1; i >= 0; i-- )
  540. X        if( i != s )
  541. X        close( i );
  542. X    open( "/", 0 );
  543. X    dup( 0 );
  544. X    dup( 0 );
  545. X    if( (i = open( "/dev/tty", 0)) >= 0 ) {
  546. X        ioctl( i, TIOCNOTTY, 0 );
  547. X        close( i );
  548. X    }
  549. X    }
  550. X
  551. X    nit_loop( s, nit_input );        /* never returns */
  552. X} /* main */
  553. X
  554. X/****************************************************************/
  555. X
  556. Xvoid
  557. Xnit_input( s, nh )
  558. X    int s;
  559. X    struct nit_hdr *nh;
  560. X{
  561. X    int l;
  562. X    struct packet *pp;
  563. X    u_char *p2, *p3;
  564. X    short f, skip;
  565. X    int len, l2;
  566. X
  567. X    l = nh->nh_datalen;
  568. X    pp = (struct packet *) (((u_char *)nh) + sizeof( struct nit_hdr ));
  569. X
  570. X    if( !etcmp( pp->p_dst, bcast ) &&
  571. X        !etcmp( pp->p_dst, mcast ) &&
  572. X        !etcmp( pp->p_dst, localaddr ) )
  573. X    return;
  574. X
  575. X    p2 = (u_char *) pp->p_data;
  576. X    skip = CTP_SHORT(p2);
  577. X
  578. X    if( skip & 1 )
  579. X    return;                /* skip must not be odd */
  580. X
  581. X    p3 = p2 + skip + 2;            /* point to data (skip skip!) */
  582. X    len = l - 14 - skip - 2;        /* length of data */
  583. X
  584. X    if( debug )
  585. X    printf("CTP skip %d.\n", skip );
  586. X    if( len < 2 )
  587. X    return;
  588. X
  589. X    f = CTP_SHORT( p3 );        /* get function */
  590. X    p3 += 2;                /* advance past function */
  591. X    len -= 2;                /* account for function length */
  592. X    switch( f ) {
  593. X    case CTP_REP:            /* reply */
  594. X    /* we're a server! */
  595. X    break;
  596. X
  597. X    case CTP_FWD:            /* forward */
  598. X    if( len < 6 ) {
  599. X        if( debug )
  600. X        printf("Too little data for FORWARD packet\n");
  601. X        return;
  602. X    }
  603. X    if( debug ) {
  604. X        printf(" FORWARD to: ");
  605. X        petaddr( p3 );        /* print ether addr */
  606. X        puts("");
  607. X    }
  608. X    if( *p3 & 0x01 ) {
  609. X        if( debug )
  610. X        printf("will not forward to multicast/broadcast\n");
  611. X        return;
  612. X    }
  613. X    skip += 6 + 2;            /* skip function and address */
  614. X    * ((u_short *)p2) = SSWAP( skip );
  615. X    bcopy( localaddr, pp->p_src, sizeof( pp->p_src ) );
  616. X    bcopy( p3, pp->p_dst, sizeof( pp->p_dst ) );
  617. X    if( nit_output( s, pp, l ) < 0 )
  618. X        perror( "nit output" );
  619. X    break;
  620. X
  621. X    default:
  622. X    if( debug )
  623. X        printf(" fncn %d.\n", f );
  624. X    break;
  625. X    }
  626. X}
  627. END_OF_ctpd.c
  628. if test 3465 -ne `wc -c <ctpd.c`; then
  629.     echo shar: \"ctpd.c\" unpacked with wrong size!
  630. fi
  631. # end of overwriting check
  632. fi
  633. if test -f dump.c -a "${1}" != "-c" ; then 
  634.   echo shar: Will not over-write existing file \"dump.c\"
  635. else
  636. echo shar: Extracting \"dump.c\" \(2113 characters\)
  637. sed "s/^X//" >dump.c <<'END_OF_dump.c'
  638. X/*
  639. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  640. X * All Rights Reserved
  641. X *
  642. X * Permission is granted to any individual or institution to use, copy,
  643. X * or redistribute this software so long as it is not sold for profit,
  644. X * provided that this notice and the original copyright notices are
  645. X * retained.  Boston University makes no representations about the
  646. X * suitability of this software for any purpose.  It is provided "as is"
  647. X * without express or implied warranty.
  648. X */
  649. X/*
  650. X *    dump.c -- dump ether traffic
  651. X *    Phil Budne @ BU/DSG
  652. X *
  653. X */
  654. X
  655. X# include <sys/types.h>
  656. X# include <sys/time.h>
  657. X# include <net/nit.h>
  658. X# include <stdio.h>
  659. X
  660. Xu_char localaddr[ 6 ];
  661. Xint count = -1;
  662. Xint promisc = 1;
  663. Xchar ibuf[100];
  664. Xchar *interface = ibuf;
  665. X
  666. Xextern int nit_snaplen;
  667. X
  668. Xmain(argc, argv)
  669. X    int argc;
  670. X    char *argv[];
  671. X{
  672. X    extern char *optarg;
  673. X    extern int optind, opterr;
  674. X    int s, c, errs, len;
  675. X    void nit_input();            /* forward */
  676. X
  677. X    errs = 0;
  678. X    len = -1;
  679. X    while( (c = getopt( argc, argv, "c:i:l:p" )) != EOF ) {
  680. X    switch( c ) {
  681. X    case 'c':
  682. X        count = atoi( optarg );
  683. X        break;
  684. X    case 'i':
  685. X        interface = optarg;
  686. X        break;
  687. X    case 'l':
  688. X        len = atoi( optarg );
  689. X        break;
  690. X    case 'p':
  691. X        promisc ^= 1;
  692. X        break;
  693. X    default:
  694. X        errs++;
  695. X    }
  696. X    }
  697. X    if( errs > 0 )
  698. X    exit( 1 );
  699. X
  700. X    if( len > 0 )
  701. X    nit_snaplen = len;
  702. X
  703. X    s = nit_open( interface, NT_ALLTYPES, localaddr, promisc );
  704. X    printf(" %s address ", interface );
  705. X    petaddr( localaddr );
  706. X    puts( "" );
  707. X
  708. X    nit_loop( s, nit_input );        /* never returns */
  709. X} /* main */
  710. X
  711. X/****************************************************************/
  712. X
  713. Xvoid
  714. Xnit_input( s, nh )
  715. X    int s;
  716. X    struct nit_hdr *nh;
  717. X{
  718. X    int l, l2;
  719. X    u_char *pp;
  720. X
  721. X    l = nh->nh_datalen;            /* wirelen? */
  722. X    pp = ((u_char *)nh) + sizeof( struct nit_hdr );
  723. X
  724. X    while( l > 0 ) {
  725. X    l2 = l;
  726. X    if( l2 > 32 )
  727. X        l2 = 32;
  728. X    pbytes( pp, l2 );
  729. X    puts("");
  730. X    pp += l2;
  731. X    l -= l2;
  732. X    }
  733. X    puts("");
  734. X
  735. X    if( count > 0 )
  736. X    if( --count == 0 )
  737. X        exit( 0 );
  738. X
  739. X}
  740. X
  741. Xpbytes( p, c )
  742. X    register u_char *p;
  743. X    register int c;
  744. X{
  745. X    while( c-- > 0 )
  746. X    puthex( *p++ & 0xff );
  747. X}
  748. END_OF_dump.c
  749. if test 2113 -ne `wc -c <dump.c`; then
  750.     echo shar: \"dump.c\" unpacked with wrong size!
  751. fi
  752. # end of overwriting check
  753. fi
  754. if test -f ether-prot.h -a "${1}" != "-c" ; then 
  755.   echo shar: Will not over-write existing file \"ether-prot.h\"
  756. else
  757. echo shar: Extracting \"ether-prot.h\" \(2308 characters\)
  758. sed "s/^X//" >ether-prot.h <<'END_OF_ether-prot.h'
  759. X/*
  760. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  761. X * All Rights Reserved
  762. X *
  763. X * Permission is granted to any individual or institution to use, copy,
  764. X * or redistribute this software so long as it is not sold for profit,
  765. X * provided that this notice and the original copyright notices are
  766. X * retained.  Boston University makes no representations about the
  767. X * suitability of this software for any purpose.  It is provided "as is"
  768. X * without express or implied warranty.
  769. X */
  770. X        Ethernet protocol types
  771. X
  772. XThe Ethernet TYPE field contains a hexadecimal number which can be
  773. Xinterpreted to yield a symbolic Ethernet protocol type name.  A table of
  774. Xsome of the major Ethernet protocol types and their descriptions follows:
  775. X
  776. XHexadecimal    Description
  777. X
  778. X0x0200        Xerox PUP
  779. X0x0201        PUP Address Trans.
  780. X0x0600        Xerox XNS IDP
  781. X0x0800        DoD IP
  782. X0x0801        X.75 Internet
  783. X0x0802        NBS Internet
  784. X0x0803        ECMA Internet
  785. X0x0804        Chaosnet
  786. X0x0805        X.25 Level 3
  787. X0x0806        ARP
  788. X0x0807        XNS Compatability
  789. X0x081C        Symbolics Private
  790. X0x0a00        Xerox 802.3 PUP
  791. X0x0a01        PUP 802.3 Address Trans.
  792. X0x1000        Berkeley trailer
  793. X0x1001        IP_trailer_1_block
  794. X0x1002        IP_trailer_2_blocks
  795. X0x1003        IP_trailer_3_blocks
  796. X0x1004        IP_trailer_4_blocks
  797. X0x1005        IP_trailer_5_blocks
  798. X0x1006        IP_trailer_6_blocks
  799. X0x1007        IP_trailer_7_blocks
  800. X0x1008        IP_trailer_8_blocks
  801. X0x1009        IP_trailer_9_blocks
  802. X0x100a        IP_trailer_10_blocks
  803. X0x100b        IP_trailer_11_blocks
  804. X0x100c        IP_trailer_12_blocks
  805. X0x100d        IP_trailer_13_blocks
  806. X0x100e        IP_trailer_14_blocks
  807. X0x100f        IP_trailer_15_blocks
  808. X0x1600        VALID
  809. X0x5208        BBN Simnet
  810. X0x6000        DECNet0
  811. X0x6001        DEC MOP Dump/Load
  812. X0x6002        DEC MOP Remote Console
  813. X0x6003        DEC DECnet Routing
  814. X0x6004        DEC LAT
  815. X0x6005        DEC DECNet Diagnostics
  816. X0x6006        DEC DECNet SCA
  817. X0x6007        DEC DECNet7
  818. X0x8003        Cronus VLN
  819. X0x8004        Cronus Direct
  820. X0x8005        HP Probe
  821. X0x8006        Nestar
  822. X0x8010        Excelan
  823. X0x8013        SGI diagnostic type
  824. X0x8014        SGI network games
  825. X0x8015        SGI reserved type
  826. X0x8016        SGI `bounce server'
  827. X0x8035        Reverse ARP
  828. X0x8038        DEC LANBridge
  829. X0x805b        Stanford V Kernel experimental
  830. X0x805c        Stanford V Kernel production
  831. X0x807c        Merit Internodal
  832. X0x8080        VitaLink bridge
  833. X0x809b        Appletalk
  834. X0x80de        TRFS (Integrated Solutions Transparent Remote File System)
  835. X0x80f3        Appletalk ARP
  836. X0x9000        Loopback
  837. X0x9001        Bridge bridge
  838. X0x9002        Bridge terminal
  839. X0xff00        BBN VITAL LANBridge
  840. END_OF_ether-prot.h
  841. if test 2308 -ne `wc -c <ether-prot.h`; then
  842.     echo shar: \"ether-prot.h\" unpacked with wrong size!
  843. fi
  844. # end of overwriting check
  845. fi
  846. if test -f hetoea.c -a "${1}" != "-c" ; then 
  847.   echo shar: Will not over-write existing file \"hetoea.c\"
  848. else
  849. echo shar: Extracting \"hetoea.c\" \(1144 characters\)
  850. sed "s/^X//" >hetoea.c <<'END_OF_hetoea.c'
  851. X/*
  852. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  853. X * All Rights Reserved
  854. X *
  855. X * Permission is granted to any individual or institution to use, copy,
  856. X * or redistribute this software so long as it is not sold for profit,
  857. X * provided that this notice and the original copyright notices are
  858. X * retained.  Boston University makes no representations about the
  859. X * suitability of this software for any purpose.  It is provided "as is"
  860. X * without express or implied warranty.
  861. X */
  862. X# include <stdio.h>
  863. X# include <netdb.h>            /* for hostent */
  864. X# include <sys/types.h>            /* for socket.h */
  865. X# include <sys/socket.h>        /* AF_INET */
  866. X
  867. Xhostenttoea( he, ea )
  868. X    struct hostent *he;
  869. X    char *ea;
  870. X{
  871. X    char **ap;
  872. X
  873. X    if( ether_hostton( he->h_name, ea ) == 0 ) /* try official name */
  874. X    return( 1 );            /* in ethers file */
  875. X    
  876. X    for( ap = he->h_aliases; *ap != NULL; ap++ )
  877. X    if( ether_hostton( *ap, ea ) == 0 ) /* try aliases in ethers file */
  878. X        return( 1 );
  879. X
  880. X    if( he->h_addrtype == AF_INET )    /* is inet host?? */
  881. X    if( iptoea( he->h_addr, ea ) )    /* try to convert to ea */
  882. X        return( 1 );
  883. X
  884. X    return( 0 );
  885. X} /* hostenttoea */
  886. END_OF_hetoea.c
  887. if test 1144 -ne `wc -c <hetoea.c`; then
  888.     echo shar: \"hetoea.c\" unpacked with wrong size!
  889. fi
  890. # end of overwriting check
  891. fi
  892. if test -f htoea.c -a "${1}" != "-c" ; then 
  893.   echo shar: Will not over-write existing file \"htoea.c\"
  894. else
  895. echo shar: Extracting \"htoea.c\" \(1908 characters\)
  896. sed "s/^X//" >htoea.c <<'END_OF_htoea.c'
  897. X/*
  898. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  899. X * All Rights Reserved
  900. X *
  901. X * Permission is granted to any individual or institution to use, copy,
  902. X * or redistribute this software so long as it is not sold for profit,
  903. X * provided that this notice and the original copyright notices are
  904. X * retained.  Boston University makes no representations about the
  905. X * suitability of this software for any purpose.  It is provided "as is"
  906. X * without express or implied warranty.
  907. X */
  908. X# include <stdio.h>
  909. X# include <netdb.h>            /* for hostent */
  910. X# include <sys/types.h>            /* for socket.h */
  911. X# include <sys/socket.h>        /* AF_INET */
  912. X# include <ctype.h>
  913. X
  914. Xhtoea( h, ea )
  915. X    char *h, *ea;
  916. X{
  917. X    struct hostent *he;
  918. X    int tempea[6], tempip;
  919. X    int i;
  920. X
  921. X    if( sscanf( h, "%x-%x-%x-%x-%x-%x",    /* Xerox/DEC/Intel format? */
  922. X            &tempea[0], &tempea[1], &tempea[2],
  923. X            &tempea[3], &tempea[4], &tempea[5] ) == 6 ||
  924. X       sscanf( h, "%x:%x:%x:%x:%x:%x",    /* BSD format? */
  925. X            &tempea[0], &tempea[1], &tempea[2],
  926. X            &tempea[3], &tempea[4], &tempea[5] ) == 6 ) {
  927. X    for( i = 0; i < 6; i++ )
  928. X        *ea++ = tempea[i] & 0xff;    /* complain if gt 8 bits? */
  929. X    return( 1 );
  930. X    }
  931. X
  932. X    if( isalpha( h[0] ) ) {
  933. X    if( ether_hostton( h, ea ) == 0 ) /* look up in /etc/ethers */
  934. X        return( 1 );        /* we win! */
  935. X
  936. X    if( (he = gethostbyname( h )) != NULL ) { /* get host ent */
  937. X        if( hostenttoea( he, ea ) )    /* look up name in /etc/hosts */
  938. X        return( 1 );
  939. X    }
  940. X
  941. X    if( strcmp( h, "BCAST" ) == 0 ) { /* do last? */
  942. X        for( i = 0; i < 6; i++ )
  943. X        *ea++ = 0xff;
  944. X        return( 1 );
  945. X    }
  946. X    }
  947. X
  948. X    /* @@ handle 96 hex digits, 48hex-48hex */
  949. X
  950. X    /* after hex format */
  951. X    if( (tempip = inet_addr( h )) != 0) { /* ip octets? */
  952. X    if( iptoea( &tempip, ea ) )
  953. X        return( 1 );
  954. X
  955. X    if( (he = gethostbyaddr( &tempip, 4, AF_INET )) != NULL )
  956. X        if( hostenttoea( he, ea ) )
  957. X        return( 1 );
  958. X    }
  959. X    return( 0 );
  960. X}
  961. END_OF_htoea.c
  962. if test 1908 -ne `wc -c <htoea.c`; then
  963.     echo shar: \"htoea.c\" unpacked with wrong size!
  964. fi
  965. # end of overwriting check
  966. fi
  967. if test -f iptoea.c -a "${1}" != "-c" ; then 
  968.   echo shar: Will not over-write existing file \"iptoea.c\"
  969. else
  970. echo shar: Extracting \"iptoea.c\" \(1779 characters\)
  971. sed "s/^X//" >iptoea.c <<'END_OF_iptoea.c'
  972. X/*
  973. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  974. X * All Rights Reserved
  975. X *
  976. X * Permission is granted to any individual or institution to use, copy,
  977. X * or redistribute this software so long as it is not sold for profit,
  978. X * provided that this notice and the original copyright notices are
  979. X * retained.  Boston University makes no representations about the
  980. X * suitability of this software for any purpose.  It is provided "as is"
  981. X * without express or implied warranty.
  982. X */
  983. X# include <sys/types.h>            /* for socket.h */
  984. X# include <sys/socket.h>        /* sockaddr */
  985. X# include <net/if.h>            /* arpreq */
  986. X# include <sys/ioctl.h>
  987. X# include <sys/errno.h>
  988. X# include <netinet/in.h>        /* sockaddr_in */
  989. Xextern int errno;
  990. X
  991. Xiptoea( ip, ea )
  992. X    long *ip;
  993. X    char *ea;
  994. X{
  995. X    struct sockaddr_in *sin;
  996. X    struct arpreq arp;
  997. X    int s, i;
  998. X
  999. X    if( (s = socket( AF_INET, SOCK_DGRAM, 0 )) < 0 )
  1000. X    return( 0 );
  1001. X
  1002. X    arp.arp_ha.sa_family = AF_UNSPEC;
  1003. X    arp.arp_pa.sa_family = AF_INET;
  1004. X    sin = (struct sockaddr_in *) &arp.arp_pa;
  1005. X    bcopy( ip, &sin->sin_addr, sizeof( *ip ) );
  1006. X
  1007. X    /* force arp */
  1008. X    sin->sin_port = 1;            /* seems unlikely */
  1009. X    if( sendto( s, &s, 0, 0, sin, sizeof( struct sockaddr_in ) ) < 0 )
  1010. X    perror( "sendto" );        /* ??ignore */
  1011. X
  1012. X    for( i = 0; i < 10; i++ ) {
  1013. X    if( ioctl( s, SIOCGARP, &arp ) < 0 ) {
  1014. X        if( errno != ENXIO ) {    /* not does not exist? */
  1015. X        perror( "ioctl" );    /* whine */
  1016. X        break;            /* leave while */
  1017. X        }
  1018. X        i++;            /* penalize for no entry yet */
  1019. X                    /* (wait longer if incomplete found) */
  1020. X    }
  1021. X    else if( arp.arp_flags & ATF_COM ) { /* complete? */
  1022. X        bcopy( arp.arp_ha.sa_data, ea, 6 );
  1023. X        close( s );
  1024. X        return( 1 );
  1025. X    } /* complete */
  1026. X    usleep( 100000 );        /* .1 sec */
  1027. X    } /* for */
  1028. X
  1029. X    close( s );
  1030. X    return( 0 );
  1031. X}
  1032. END_OF_iptoea.c
  1033. if test 1779 -ne `wc -c <iptoea.c`; then
  1034.     echo shar: \"iptoea.c\" unpacked with wrong size!
  1035. fi
  1036. # end of overwriting check
  1037. fi
  1038. if test -f mfgr.h -a "${1}" != "-c" ; then 
  1039.   echo shar: Will not over-write existing file \"mfgr.h\"
  1040. else
  1041. echo shar: Extracting \"mfgr.h\" \(598 characters\)
  1042. sed "s/^X//" >mfgr.h <<'END_OF_mfgr.h'
  1043. X/*
  1044. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  1045. X * All Rights Reserved
  1046. X *
  1047. X * Permission is granted to any individual or institution to use, copy,
  1048. X * or redistribute this software so long as it is not sold for profit,
  1049. X * provided that this notice and the original copyright notices are
  1050. X * retained.  Boston University makes no representations about the
  1051. X * suitability of this software for any purpose.  It is provided "as is"
  1052. X * without express or implied warranty.
  1053. X */
  1054. Xtypedef struct mfgr {
  1055. X    unsigned long mf_code;
  1056. X    char *mf_name;
  1057. X} MFGR;
  1058. X
  1059. Xextern MFGR mfgrs[];
  1060. END_OF_mfgr.h
  1061. if test 598 -ne `wc -c <mfgr.h`; then
  1062.     echo shar: \"mfgr.h\" unpacked with wrong size!
  1063. fi
  1064. # end of overwriting check
  1065. fi
  1066. if test -f mfgrs.c -a "${1}" != "-c" ; then 
  1067.   echo shar: Will not over-write existing file \"mfgrs.c\"
  1068. else
  1069. echo shar: Extracting \"mfgrs.c\" \(3024 characters\)
  1070. sed "s/^X//" >mfgrs.c <<'END_OF_mfgrs.c'
  1071. X/*
  1072. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  1073. X * All Rights Reserved
  1074. X *
  1075. X * Permission is granted to any individual or institution to use, copy,
  1076. X * or redistribute this software so long as it is not sold for profit,
  1077. X * provided that this notice and the original copyright notices are
  1078. X * retained.  Boston University makes no representations about the
  1079. X * suitability of this software for any purpose.  It is provided "as is"
  1080. X * without express or implied warranty.
  1081. X */
  1082. X# include "mfgr.h"
  1083. X
  1084. XMFGR mfgrs[] = {
  1085. X    0x00000c,    "W.D.",            /* Western Digital */
  1086. X    0x00002a,    "TRW",
  1087. X    0x00005a,    "S&Koch",
  1088. X    0x000093,    "Proteon",
  1089. X    0x000093,    "Ameristar",        /* Ameristar Tech. */
  1090. X    0x0000aa,    "Xerox",
  1091. X    0x0000c0,    "W.D.",            /* ? */
  1092. X    0x0000dd,    "Gould",
  1093. X    0x000102,    "BBN",            /* unofficial */
  1094. X    0x001700,    "Kabel",
  1095. X    0x00dd00,    "U-B",            /* seen in PC/RT */
  1096. X    0x00dd01,    "U-B",            /* seen in IBM 8232 (2273A board) */
  1097. X    0x020701,    "Interlan",        /* (UNIBUS/QBUS), Apollo */
  1098. X    0x020406,    "BBN",            /* unofficial */
  1099. X    0x02608c,    "3Com",            /* (PC/Imagen/Valid) */
  1100. X    0x02cf1f,    "CMC",            /* (Masscomp/SGI) */
  1101. X    0x080002,    "Bridge",
  1102. X    0x080005,    "Symbolics",
  1103. X    0x080008,    "BBN",
  1104. X    0x080009,    "H-P",
  1105. X    0x080010,    "AT+T",            /* ?? */
  1106. X    0x080014,    "Excelan",        /* (BBN Butterfly/Masscomp/Iris) */
  1107. X    0x08001a,    "DG",
  1108. X    0x08001b,    "DG",
  1109. X    0x08001e,    "Apollo",
  1110. X    0x080020,    "Sun",
  1111. X    0x080028,    "TI",            /* TI Explorer */
  1112. X    0x08002b,    "DEC",            /* UNIBUS/QBUS/VAX/LANBridge */
  1113. X                    /* DEUNA, DEQNA, DELUA */
  1114. X
  1115. X    0x080045,    "???",
  1116. X    0x080047,    "Sequent",
  1117. X    0x080049,    "Univation",
  1118. X    0x08004c,    "Encore",
  1119. X    0x08004e,    "BICC",
  1120. X    0x080068,    "Ridge",
  1121. X    0x080069,    "SGI",            /* Silicon Graphics */
  1122. X    0x08006e,    "Excelan",
  1123. X    0x08007c,    "Vitalink",        /* TransLAN III */
  1124. X    0x080089,    "Kinetics",
  1125. X    0x08008b,    "Pyramid",
  1126. X    0x08008d,    "XyVision",
  1127. X    0x090090,    "H-P",            /* MULTICAST */
  1128. X    0x09002b,    "LanBridge",        /* MULTICAST */
  1129. X    /* 01-00-00 LanBridge Copy */
  1130. X    /* 01-00-01 LanBridge Hello (1/sec)*/
  1131. X
  1132. X    0x800010,    "AT+T",            /* 3b2 3Bnet card */
  1133. X    0xaa0003,    "DEC",            /* DEUNA/KLNI */
  1134. X    0xaa0004,    "DECNET",        /* logical address */
  1135. X
  1136. X    0xab0000,      "DEC multcast",        /* MULTICAST */
  1137. X    /*
  1138. X     * lower part
  1139. X     * 01-00-00 DL-MOP             Dump/Load assist
  1140. X     * 02-00-00 RE-MOP             Remote console sys id (1 every 8-10min)
  1141. X     *                    from LanBridge, DEUNA, DELUA, DEQNA*
  1142. X     * 03-00-00    DECnet phase IV        end node hello (1 every 15 sec)
  1143. X     * 04-00-00    DECnet phase IV        router hello (1 every 15 sec)
  1144. X     * 
  1145. X     */
  1146. X
  1147. X    0xab0001,      "DEC ??",        /* reserved MULTICAST */
  1148. X    0xab0002,      "DEC ??",        /* reserved MULTICAST */
  1149. X
  1150. X    0xab0003,    "LAT",            /* MULTICAST */
  1151. X    /* low octets? */
  1152. X
  1153. X    0xab0004,      "DEC",            /* reserved MULTICAST */
  1154. X    /*
  1155. X     * 00-00-00 thru
  1156. X     * ff-ff-ff reserved for customer??
  1157. X     * 01-xx-yy LAVC Cluster group yy??
  1158. X     */
  1159. X    0xc00000,    "Western Digital?",    /* ?? */
  1160. X    0xcf0000,    "CTP",            /* MULTICAST */
  1161. X    0,        ""
  1162. X};
  1163. X
  1164. Xint nmfgrs = ( sizeof( mfgrs ) / sizeof( MFGR ) ) - 1;
  1165. END_OF_mfgrs.c
  1166. if test 3024 -ne `wc -c <mfgrs.c`; then
  1167.     echo shar: \"mfgrs.c\" unpacked with wrong size!
  1168. fi
  1169. # end of overwriting check
  1170. fi
  1171. if test -f ns.c -a "${1}" != "-c" ; then 
  1172.   echo shar: Will not over-write existing file \"ns.c\"
  1173. else
  1174. echo shar: Extracting \"ns.c\" \(3818 characters\)
  1175. sed "s/^X//" >ns.c <<'END_OF_ns.c'
  1176. X/*
  1177. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  1178. X * All Rights Reserved
  1179. X *
  1180. X * Permission is granted to any individual or institution to use, copy,
  1181. X * or redistribute this software so long as it is not sold for profit,
  1182. X * provided that this notice and the original copyright notices are
  1183. X * retained.  Boston University makes no representations about the
  1184. X * suitability of this software for any purpose.  It is provided "as is"
  1185. X * without express or implied warranty.
  1186. X */
  1187. X/*
  1188. X *    ns.c -- name server crock
  1189. X *    Phil Budne @ Boston U / Distributed Systems
  1190. X *    September 1986
  1191. X */
  1192. X
  1193. X# include <stdio.h>
  1194. X# include <netdb.h>
  1195. X# include <sys/types.h>
  1196. X# include <sys/socket.h>
  1197. X# include <netinet/in.h>
  1198. X# include <arpa/inet.h>
  1199. X# include <signal.h>
  1200. X# include <setjmp.h>
  1201. X
  1202. X# ifndef DEBUGF
  1203. X# define DEBUGF 0            /* non-zero to debug */
  1204. X# endif /* DEBUGF not defined */
  1205. X
  1206. Xextern char *malloc(), *strcpy();
  1207. X
  1208. X# define TABLE_SIZE 200
  1209. Xstruct table {
  1210. X    unsigned long table_addr;
  1211. X    char *table_name;
  1212. X} table[ TABLE_SIZE ];
  1213. Xint table_pointer = 0;
  1214. X
  1215. X# define NS_ADDR 0x80c51428        /* bu-it-itnet */
  1216. X# define NS_PORT 53
  1217. X
  1218. Xchar *jname;                /* argv[0] */
  1219. X
  1220. Xstruct domain {
  1221. X    short id, op, qc, ac, nc, dc;
  1222. X    char qa[1];
  1223. X};
  1224. X
  1225. Xstruct qsuf {
  1226. X    short type, class;
  1227. X};
  1228. X
  1229. X# define cat(t,f){register int l = strlen(f);*t++ = l; strcpy(t,f);t+=l;}
  1230. X
  1231. Xint s;
  1232. Xinited = 0;
  1233. X
  1234. Xchar *ns_lookup( addr )
  1235. Xunsigned long addr;
  1236. X{
  1237. X    struct sockaddr_in sin;
  1238. X    char buf[ 128 ];            /* short query! */
  1239. X    register struct domain *dp;
  1240. X    register char *p;
  1241. X    register struct qsuf *q;
  1242. X    char name[ 100 ];
  1243. X
  1244. X    if( !inited && (s = socket( AF_INET, SOCK_DGRAM, 0)) < 0 )
  1245. X    return NULL;
  1246. X    inited = 1;
  1247. X
  1248. X    sin.sin_family = AF_INET;
  1249. X    sin.sin_port = htons( NS_PORT );
  1250. X    sin.sin_addr.s_addr = htonl( NS_ADDR );
  1251. X
  1252. X    dp = (struct domain *) buf;
  1253. X    dp->id = 0;
  1254. X    dp->op = htons( 0400 );        /* please recurse */
  1255. X    dp->qc = htons( 1 );        /* just one question... */
  1256. X    dp->ac = dp->nc = dp->dc = 0;
  1257. X    p = dp->qa;
  1258. X
  1259. X    sprintf( name, "%d", addr & 255 );
  1260. X    cat(p, name );
  1261. X    sprintf( name, "%d", (addr >> 8) & 255 );
  1262. X    cat(p, name );
  1263. X    sprintf( name, "%d", (addr >> 16) & 255 );
  1264. X    cat(p, name );
  1265. X    sprintf( name, "%d", (addr >> 24) & 255 );
  1266. X    cat(p, name );
  1267. X    cat(p, "in-addr" );
  1268. X    cat(p, "arpa" );
  1269. X    *p++ = '\0';
  1270. X
  1271. X    q = (struct qsuf *) p;
  1272. X    q->type = htons( 12 );        /* domain name pointer */
  1273. X    q->class = htons( 1 );        /* the internet */
  1274. X    p += sizeof( struct qsuf );
  1275. X
  1276. X# if DEBUGF
  1277. X    printf( "to %s port %d\n",
  1278. X       inet_ntoa( sin.sin_addr.s_addr ), ntohs( sin.sin_port ) );
  1279. X# endif /* DEBUGF */
  1280. X
  1281. X    /* TIMEOUT!!!! */
  1282. X    if( sendto( s, buf, p - buf, 0, &sin, sizeof( sin ) ) < 0 ||
  1283. X       read( s, buf, sizeof( buf ) ) < 0 ) {
  1284. X    close( s );
  1285. X    inited = 0;
  1286. X    return NULL;
  1287. X    }
  1288. X
  1289. X    if( ntohs( dp->op ) & 017 || ntohs( dp->ac ) <= 0 )
  1290. X    return NULL;
  1291. X    else {
  1292. X    while( *p != '\0' )
  1293. X        if( *p & 0300 )        /* compressed? */
  1294. X        *++p = '\0';
  1295. X        else
  1296. X        p += *p + 1;
  1297. X        p += 10 + 1;        /* rsrc record heading len */
  1298. X
  1299. X
  1300. X    name[0] = '\0';
  1301. X    while( *p != '\0' ) {
  1302. X        if( *p & 0300 )        /* compressed? */
  1303. X        p = buf + (ntohs( * (int *)p ) & 037777);
  1304. X        else {
  1305. X        strncat( name, p+1, *p );
  1306. X        strcat( name, "." );
  1307. X        p += *p + 1;
  1308. X        }
  1309. X    }
  1310. X
  1311. X    if( strlen( name ) )
  1312. X        name[ strlen( name ) - 1 ] = '\0';
  1313. X
  1314. X    return( strcpy( malloc( strlen( name ) + 1 ), name ) );
  1315. X    }
  1316. X} /* ns_lookup */
  1317. X
  1318. Xchar *lookup_name( addr )
  1319. X    unsigned long addr;
  1320. X{
  1321. X    register int i;
  1322. X    char *n;
  1323. X
  1324. X    for( i = 0; i < table_pointer; i++ )
  1325. X    if( addr == table[ i ].table_addr )
  1326. X        return( table[ i ].table_name );
  1327. X
  1328. X    n = ns_lookup( addr );
  1329. X
  1330. X    if( table_pointer == TABLE_SIZE - 1 )
  1331. X    return n;
  1332. X
  1333. X/*  if( n == NULL ) return NULL;    /* cache failures too! */
  1334. X
  1335. X    table[ table_pointer ].table_name = n;
  1336. X    table[ table_pointer++ ].table_addr = addr;
  1337. X    return( n );
  1338. X}
  1339. X
  1340. END_OF_ns.c
  1341. if test 3818 -ne `wc -c <ns.c`; then
  1342.     echo shar: \"ns.c\" unpacked with wrong size!
  1343. fi
  1344. # end of overwriting check
  1345. fi
  1346. if test -f pbytes.c -a "${1}" != "-c" ; then 
  1347.   echo shar: Will not over-write existing file \"pbytes.c\"
  1348. else
  1349. echo shar: Extracting \"pbytes.c\" \(601 characters\)
  1350. sed "s/^X//" >pbytes.c <<'END_OF_pbytes.c'
  1351. X/*
  1352. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  1353. X * All Rights Reserved
  1354. X *
  1355. X * Permission is granted to any individual or institution to use, copy,
  1356. X * or redistribute this software so long as it is not sold for profit,
  1357. X * provided that this notice and the original copyright notices are
  1358. X * retained.  Boston University makes no representations about the
  1359. X * suitability of this software for any purpose.  It is provided "as is"
  1360. X * without express or implied warranty.
  1361. X */
  1362. X
  1363. Xpbytes( p, c )
  1364. X    unsigned char *p;
  1365. X    int c;
  1366. X{
  1367. X    while( c-- > 0 )
  1368. X    puthex( (unsigned)*p++ );
  1369. X}
  1370. END_OF_pbytes.c
  1371. if test 601 -ne `wc -c <pbytes.c`; then
  1372.     echo shar: \"pbytes.c\" unpacked with wrong size!
  1373. fi
  1374. # end of overwriting check
  1375. fi
  1376. if test -f petaddr.c -a "${1}" != "-c" ; then 
  1377.   echo shar: Will not over-write existing file \"petaddr.c\"
  1378. else
  1379. echo shar: Extracting \"petaddr.c\" \(880 characters\)
  1380. sed "s/^X//" >petaddr.c <<'END_OF_petaddr.c'
  1381. X/*
  1382. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  1383. X * All Rights Reserved
  1384. X *
  1385. X * Permission is granted to any individual or institution to use, copy,
  1386. X * or redistribute this software so long as it is not sold for profit,
  1387. X * provided that this notice and the original copyright notices are
  1388. X * retained.  Boston University makes no representations about the
  1389. X * suitability of this software for any purpose.  It is provided "as is"
  1390. X * without express or implied warranty.
  1391. X */
  1392. X# include <stdio.h>
  1393. X
  1394. Xpetaddr( a )                /* print ether addr */
  1395. X    register unsigned char *a;
  1396. X{
  1397. X    puthex( (unsigned)a[0] );
  1398. X    putchar('-');
  1399. X    puthex( (unsigned)a[1] );
  1400. X    putchar('-');
  1401. X    puthex( (unsigned)a[2] );
  1402. X    putchar('-');
  1403. X    puthex( (unsigned)a[3] );
  1404. X    putchar('-');
  1405. X    puthex( (unsigned)a[4] );
  1406. X    putchar('-');
  1407. X    puthex( (unsigned)a[5] );
  1408. X
  1409. X} /* petaddr */
  1410. END_OF_petaddr.c
  1411. if test 880 -ne `wc -c <petaddr.c`; then
  1412.     echo shar: \"petaddr.c\" unpacked with wrong size!
  1413. fi
  1414. # end of overwriting check
  1415. fi
  1416. if test -f petaddrm.c -a "${1}" != "-c" ; then 
  1417.   echo shar: Will not over-write existing file \"petaddrm.c\"
  1418. else
  1419. echo shar: Extracting \"petaddrm.c\" \(651 characters\)
  1420. sed "s/^X//" >petaddrm.c <<'END_OF_petaddrm.c'
  1421. X/*
  1422. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  1423. X * All Rights Reserved
  1424. X *
  1425. X * Permission is granted to any individual or institution to use, copy,
  1426. X * or redistribute this software so long as it is not sold for profit,
  1427. X * provided that this notice and the original copyright notices are
  1428. X * retained.  Boston University makes no representations about the
  1429. X * suitability of this software for any purpose.  It is provided "as is"
  1430. X * without express or implied warranty.
  1431. X */
  1432. X# include <stdio.h>
  1433. X
  1434. Xpetaddrm( ea )
  1435. X    char *ea;
  1436. X{
  1437. X    petaddr( ea );
  1438. X    putchar( ' ' );
  1439. X    putchar( '(' );
  1440. X    petmf( ea );
  1441. X    putchar( ')' );
  1442. X}
  1443. X
  1444. END_OF_petaddrm.c
  1445. if test 651 -ne `wc -c <petaddrm.c`; then
  1446.     echo shar: \"petaddrm.c\" unpacked with wrong size!
  1447. fi
  1448. # end of overwriting check
  1449. fi
  1450. if test -f petmf.c -a "${1}" != "-c" ; then 
  1451.   echo shar: Will not over-write existing file \"petmf.c\"
  1452. else
  1453. echo shar: Extracting \"petmf.c\" \(1301 characters\)
  1454. sed "s/^X//" >petmf.c <<'END_OF_petmf.c'
  1455. X/*
  1456. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  1457. X * All Rights Reserved
  1458. X *
  1459. X * Permission is granted to any individual or institution to use, copy,
  1460. X * or redistribute this software so long as it is not sold for profit,
  1461. X * provided that this notice and the original copyright notices are
  1462. X * retained.  Boston University makes no representations about the
  1463. X * suitability of this software for any purpose.  It is provided "as is"
  1464. X * without express or implied warranty.
  1465. X */
  1466. X# include <stdio.h>
  1467. X# include "mfgr.h"
  1468. X
  1469. Xpetmf( a )                /* print ether mfgr name */
  1470. X    register unsigned char *a;
  1471. X{
  1472. X    long mfc;
  1473. X    register MFGR *mf;
  1474. X
  1475. X    mfc = (((a[0] << 8) + a[1]) << 8) + a[2]; /* top 24 bits */
  1476. X
  1477. X    /* check for IEEE "local" bit??? @@ */
  1478. X    if( *a & 1 ) {            /* logical address? */
  1479. X    register int broadcast, i;
  1480. X
  1481. X    broadcast = 1;            /* set true */
  1482. X    for( i = 0; broadcast && i < 6; i++ )
  1483. X        if( a[i] != 0xff )
  1484. X        broadcast = 0;
  1485. X
  1486. X    if( broadcast )
  1487. X        printf( "broadcast" );
  1488. X    else
  1489. X        printf( "%smulticast", "" /* lookup registry of mfc */ );
  1490. X    return;
  1491. X    } /* logical */
  1492. X
  1493. X    /* @@TLU */
  1494. X    for( mf = mfgrs; mf->mf_code != 0; mf++ )
  1495. X    if( mf->mf_code == mfc ) {
  1496. X        printf( "%s", mf->mf_name );
  1497. X        return;
  1498. X    }
  1499. X    else if( mf->mf_code > mfc )
  1500. X        break;
  1501. X
  1502. X    printf( "unknown");
  1503. X}
  1504. END_OF_petmf.c
  1505. if test 1301 -ne `wc -c <petmf.c`; then
  1506.     echo shar: \"petmf.c\" unpacked with wrong size!
  1507. fi
  1508. # end of overwriting check
  1509. fi
  1510. if test -f pipaddr.c -a "${1}" != "-c" ; then 
  1511.   echo shar: Will not over-write existing file \"pipaddr.c\"
  1512. else
  1513. echo shar: Extracting \"pipaddr.c\" \(840 characters\)
  1514. sed "s/^X//" >pipaddr.c <<'END_OF_pipaddr.c'
  1515. X/*
  1516. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  1517. X * All Rights Reserved
  1518. X *
  1519. X * Permission is granted to any individual or institution to use, copy,
  1520. X * or redistribute this software so long as it is not sold for profit,
  1521. X * provided that this notice and the original copyright notices are
  1522. X * retained.  Boston University makes no representations about the
  1523. X * suitability of this software for any purpose.  It is provided "as is"
  1524. X * without express or implied warranty.
  1525. X */
  1526. X# include "packet.h"
  1527. Xint use_nameserver = 1;
  1528. X# define NULL ((char *)0)
  1529. X
  1530. Xpipaddr( f, i )
  1531. X    int f;
  1532. X    ip_addr i;
  1533. X{
  1534. X    char *n, *lookup_name();
  1535. X    if( f && use_nameserver && (n = lookup_name( i )) != NULL )
  1536. X    printf("%s", n );
  1537. X    else
  1538. X    printf("%d.%d.%d.%d",
  1539. X       (i >> 24) & 255,
  1540. X       (i >> 16) & 255,
  1541. X       (i >> 8) & 255,
  1542. X       i & 255 );
  1543. X}
  1544. X
  1545. END_OF_pipaddr.c
  1546. if test 840 -ne `wc -c <pipaddr.c`; then
  1547.     echo shar: \"pipaddr.c\" unpacked with wrong size!
  1548. fi
  1549. # end of overwriting check
  1550. fi
  1551. if test -f protocol.h -a "${1}" != "-c" ; then 
  1552.   echo shar: Will not over-write existing file \"protocol.h\"
  1553. else
  1554. echo shar: Extracting \"protocol.h\" \(4935 characters\)
  1555. sed "s/^X//" >protocol.h <<'END_OF_protocol.h'
  1556. X/*
  1557. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  1558. X * All Rights Reserved
  1559. X *
  1560. X * Permission is granted to any individual or institution to use, copy,
  1561. X * or redistribute this software so long as it is not sold for profit,
  1562. X * provided that this notice and the original copyright notices are
  1563. X * retained.  Boston University makes no representations about the
  1564. X * suitability of this software for any purpose.  It is provided "as is"
  1565. X * without express or implied warranty.
  1566. X */
  1567. Xstruct protocol {
  1568. X    unsigned short pr_type;
  1569. X    char *pr_short;
  1570. X    char *pr_name;
  1571. X} protocols[] = {
  1572. X    0x0200,    "PUP",        "Xerox PUP", /* 802.3 length!! */
  1573. X    0x0201,    "PUPAT",    "Xerox PUP Addr. Trans.", /* 802.3 length!! */
  1574. X    0x0600,    "XNS",        "Xerox NS (XNS) IDP",
  1575. X    0x0800,    "IP",        "DoD IP",
  1576. X    0x0801,    "X.75",        "X.75 Internet",
  1577. X    0x0802,    "NBS",        "NBS Internet",
  1578. X    0x0803,    "ECMA",        "ECMA Internet",
  1579. X    0x0804,    "Chaos",    "Chaosnet",
  1580. X    0x0805,    "X.25",        "X.25 Level 3",
  1581. X    0x0806,    "ARP",        "Address Resolution Protocol (ARP)",
  1582. X    0x0807,    "XNScomp",    "XNS Compatibility",
  1583. X    0x081c,    "Symbolics",    "Symbolics Private",
  1584. X    0x0888,    "Xyplex",    "Xyplex",
  1585. X    0x0a00,    "PUP2",        "802.3 Xerox PUP",
  1586. X    0x0a01,    "PUPAT2",    "802.3 PUP Address Translation",
  1587. X    0x0bad,    "Banyan",    "Banyan Systems",
  1588. X    0x1000,    "TRAIL0",    "Berkeley Trailer negotiation",
  1589. X    0x1001,    "TRAIL1",    "Berkeley Trailer 1",
  1590. X    0x1002,    "TRAIL2",    "Berkeley Trailer 2",
  1591. X    0x1003,    "TRAIL3",    "Berkeley Trailer 3",
  1592. X    0x1004,    "TRAIL4",    "Berkeley Trailer 4",
  1593. X    0x1005,    "TRAIL5",    "Berkeley Trailer 5",
  1594. X    0x1006,    "TRAIL6",    "Berkeley Trailer 6",
  1595. X    0x1007,    "TRAIL7",    "Berkeley Trailer 7",
  1596. X    0x1008,    "TRAIL8",    "Berkeley Trailer 8",
  1597. X    0x1009,    "TRAIL9",    "Berkeley Trailer 9",
  1598. X    0x100a,    "TRAIL10",    "Berkeley Trailer 10",
  1599. X    0x100b,    "TRAIL11",    "Berkeley Trailer 11",
  1600. X    0x100c,    "TRAIL12",    "Berkeley Trailer 12",
  1601. X    0x100d,    "TRAIL13",    "Berkeley Trailer 13",
  1602. X    0x100e,    "TRAIL14",    "Berkeley Trailer 14",
  1603. X    0x100f,    "TRAIL15",    "Berkeley Trailer 15",
  1604. X    0x1600,    "VALID",    "VALID",
  1605. X    0x5208,    "Simnet",    "BBN Simnet Private",
  1606. X    0x6000,    "DEC XP",    "DEC XP",
  1607. X    0x6001,    "DEC DL-MOP",    "DEC Dump/Load Maintenance Operation Protocol",
  1608. X    0x6002,    "DEC RE-MOP",     "DEC Remote Console Maintenance Operation",
  1609. X    0x6003,    "DECnet",    "DECNET Phase IV",
  1610. X    0x6004,    "LAT",        "DEC LAT - Local Area Transport",
  1611. X    0x6005,    "DEC diag?",    "DEC interface initialization / diagnostics?",
  1612. X    0x6006,    "DEC customer",    "DEC customer use",
  1613. X    0x6007,    "DEC SCA/LAVC",    "DEC Sy. Comm. Arch. / Local Area VAX Cluster",
  1614. X    0x6008,    "DEC ??",    "DEC unassigned",
  1615. X    0x6009,    "DEC ??",    "DEC unassigned",
  1616. X    0x7000,    "UB/down",    "Ungerman Bass download",
  1617. X    0x7002,    "UB/diag",    "Ungerman Bass diag/loopback",
  1618. X    0x7030,    "Interlan",    "Interlan 3010 test packet?",
  1619. X    0x8003,    "Cronus VLN",    "Cronus VLN",
  1620. X    0x8004,    "Cronus Direct","Cronus Direct",
  1621. X    0x8005,    "HP Probe",    "HP Probe protocol",
  1622. X    0x8006,    "Nestar",    "Nestar",
  1623. X    0x8008,    "3BNET",    "ATT 3BNET",
  1624. X    0x8010,    "Excelan",    "Excelan",
  1625. X    0x8013,    "SGI diag",    "Silicon Graphics diagnostic",
  1626. X    0x8014,    "SGI games",    "Silicon Graphics network games",
  1627. X    0x8015,    "SGI reserved",    "Silicon Graphics reserved type",
  1628. X    0x8016,    "SGI bounce",    "Silicon Graphics XNS nameserver/bounce",
  1629. X    0x8019,    "Apollo",    "Apollo DOMAIN",
  1630. X    0x8035,    "RARP",        "Reverse ARP",
  1631. X    0x8038,    "DEBET",    "DEC LanBridge (Debet) Management",
  1632. X    0x8039,    "DEC ?",    "DEC unassigned",
  1633. X    0x803a,    "DEC ?",    "DEC unassigned",
  1634. X    0x803b,    "DEC ?",    "DEC unassigned",
  1635. X    0x803c,    "DEC ?",    "DEC unassigned",
  1636. X    0x803d,    "DEC EEP",    "DEC Ethernet Encryption Protocol",
  1637. X    0x803e,    "DEC ?",    "DEC unassigned",
  1638. X    0x803f,    "DEC LTM",    "DEC Lan Traffic Monitor",
  1639. X    0x8040,    "DEC ?",    "DEC unassigned",
  1640. X    0x8041,    "DEC ?",    "DEC unassigned",
  1641. X    0x8042,    "DEC ?",    "DEC unassigned",
  1642. X    0x805b,    "exp. V",    "Stanford V Kernel experimental",
  1643. X    0x805c,    "prod. V",    "Stanford V Kernel production",
  1644. X    0x807c,    "Merit",    "Merit Internodal",
  1645. X    0x807d,    "Vitalink ?",    "Vitalink ?",
  1646. X    0x807e,    "Vitalink ?",    "Vitalink ?",
  1647. X    0x807f,    "Vitalink ?",    "Vitalink ?",
  1648. X    0x8080,    "Vitalink mgmt","Vitalink TransLAN III bridge mgmt",
  1649. X    0x809b,    "EtherTalk",    "Ethernet/AppleTalk",
  1650. X    0x809c,    "EtherTalk Arp","Ethernet/AppleTalk Arp", /* ?? */
  1651. X    0x80de,    "TRFS",        "Integrated Solutions Transparent Remote File System",
  1652. X    0x80f3,    "Appletalk ARP?","Appletalk ARP??", /* ?? */
  1653. X    0x8107,    "Symbolics",    "Symbolics Private",
  1654. X    0x8108,    "Symbolics",    "Symbolics Private",
  1655. X    0x8109,    "Symbolics",    "Symbolics Private",
  1656. X    0x8137,    "Novell",    "Novell", /* netware?? */
  1657. X    0x9000,    "CTP",        "Configuration Test Protocol (CTP) Loopback",
  1658. X    0x9001,    "BRIDGEbridge",    "BRIDGE bridge mgmt", /* XNS mgmt? */
  1659. X    0x9002,    "BRIDGEterm",    "BRIDGE terminal server", /* TCP/IP mgmt? */
  1660. X    0xff00,    "VITAL",    "BBN VITAL LANBridge cache wakeups",
  1661. X    0,        ""
  1662. X};
  1663. X
  1664. X# define NPROTO (((sizeof protocols)/(sizeof( struct protocol )))-1)
  1665. END_OF_protocol.h
  1666. if test 4935 -ne `wc -c <protocol.h`; then
  1667.     echo shar: \"protocol.h\" unpacked with wrong size!
  1668. fi
  1669. # end of overwriting check
  1670. fi
  1671. if test -f puthex.c -a "${1}" != "-c" ; then 
  1672.   echo shar: Will not over-write existing file \"puthex.c\"
  1673. else
  1674. echo shar: Extracting \"puthex.c\" \(681 characters\)
  1675. sed "s/^X//" >puthex.c <<'END_OF_puthex.c'
  1676. X/*
  1677. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  1678. X * All Rights Reserved
  1679. X *
  1680. X * Permission is granted to any individual or institution to use, copy,
  1681. X * or redistribute this software so long as it is not sold for profit,
  1682. X * provided that this notice and the original copyright notices are
  1683. X * retained.  Boston University makes no representations about the
  1684. X * suitability of this software for any purpose.  It is provided "as is"
  1685. X * without express or implied warranty.
  1686. X */
  1687. X# include <stdio.h>
  1688. X
  1689. Xputhex( i )
  1690. X    register unsigned i;
  1691. X{
  1692. X    static char hecks[] = "0123456789ABCDEF";
  1693. X    putchar( hecks[ (i >> 4) & 0xf ] );
  1694. X    putchar( hecks[ i & 0xf ] );
  1695. X}
  1696. END_OF_puthex.c
  1697. if test 681 -ne `wc -c <puthex.c`; then
  1698.     echo shar: \"puthex.c\" unpacked with wrong size!
  1699. fi
  1700. # end of overwriting check
  1701. fi
  1702. if test -f samecount.c -a "${1}" != "-c" ; then 
  1703.   echo shar: Will not over-write existing file \"samecount.c\"
  1704. else
  1705. echo shar: Extracting \"samecount.c\" \(812 characters\)
  1706. sed "s/^X//" >samecount.c <<'END_OF_samecount.c'
  1707. X/*
  1708. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  1709. X * All Rights Reserved
  1710. X *
  1711. X * Permission is granted to any individual or institution to use, copy,
  1712. X * or redistribute this software so long as it is not sold for profit,
  1713. X * provided that this notice and the original copyright notices are
  1714. X * retained.  Boston University makes no representations about the
  1715. X * suitability of this software for any purpose.  It is provided "as is"
  1716. X * without express or implied warranty.
  1717. X */
  1718. Xmain() {
  1719. X    char line[2][ 1000 ];
  1720. X    int i, j, c;
  1721. X
  1722. X    i = 0;
  1723. X    c = 0;
  1724. X    while( gets( line[i] ) ) {
  1725. X    j = (i + 1) & 1;
  1726. X    if( strcmp( line[i], line[j] ) == 0 )
  1727. X        c++;
  1728. X    else if( c > 0 ) {
  1729. X        printf("%5d %s\n", c, line[j] );
  1730. X        c = 1;
  1731. X    }
  1732. X    i = j;
  1733. X    }
  1734. X    if( c > 0 )
  1735. X    printf("%5d %s\n", c, line[i] );
  1736. X}
  1737. END_OF_samecount.c
  1738. if test 812 -ne `wc -c <samecount.c`; then
  1739.     echo shar: \"samecount.c\" unpacked with wrong size!
  1740. fi
  1741. # end of overwriting check
  1742. fi
  1743. if test -f show.c -a "${1}" != "-c" ; then 
  1744.   echo shar: Will not over-write existing file \"show.c\"
  1745. else
  1746. echo shar: Extracting \"show.c\" \(3211 characters\)
  1747. sed "s/^X//" >show.c <<'END_OF_show.c'
  1748. X/*
  1749. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  1750. X * All Rights Reserved
  1751. X *
  1752. X * Permission is granted to any individual or institution to use, copy,
  1753. X * or redistribute this software so long as it is not sold for profit,
  1754. X * provided that this notice and the original copyright notices are
  1755. X * retained.  Boston University makes no representations about the
  1756. X * suitability of this software for any purpose.  It is provided "as is"
  1757. X * without express or implied warranty.
  1758. X */
  1759. X/*
  1760. X *    show.c -- show ctp traffic
  1761. X *    Phil Budne @ BU/DSG
  1762. X *
  1763. X *    NOTE: user mode ctpd robs replies (?)
  1764. X */
  1765. X
  1766. X# include <sys/types.h>
  1767. X# include <sys/time.h>
  1768. X# include <net/nit.h>
  1769. X# include <stdio.h>
  1770. X# include "ctp.h"
  1771. X
  1772. Xstruct packet {
  1773. X    u_char  p_dst[ 6 ];
  1774. X    u_char  p_src[ 6 ];
  1775. X    u_short p_type;
  1776. X    u_char  p_data[ 2048 ];
  1777. X};
  1778. X
  1779. Xu_char localaddr[ 6 ];
  1780. Xint count = -1;
  1781. Xint promisc = 1;
  1782. Xchar *interface = "ie0";
  1783. X
  1784. Xmain(argc, argv)
  1785. X    int argc;
  1786. X    char *argv[];
  1787. X{
  1788. X    extern char *optarg;
  1789. X    extern int optind, opterr;
  1790. X    int s, c, errs;
  1791. X    void nit_input();            /* forward */
  1792. X
  1793. X    errs = 0;
  1794. X    while( (c = getopt( argc, argv, "c:i:p" )) != EOF ) {
  1795. X    switch( c ) {
  1796. X    case 'c':
  1797. X        count = atoi( optarg );
  1798. X        break;
  1799. X    case 'i':
  1800. X        interface = optarg;
  1801. X        break;
  1802. X    case 'p':
  1803. X        promisc ^= 1;
  1804. X        break;
  1805. X    default:
  1806. X        errs++;
  1807. X    }
  1808. X    }
  1809. X    if( errs > 0 )
  1810. X    exit( 1 );
  1811. X
  1812. X    /*NT_ALLTYPES*/
  1813. X    s = nit_open( interface, ETHERTYPE_CTP, localaddr, promisc );
  1814. X    printf("%s address ", interface );
  1815. X    petaddr( localaddr );
  1816. X    puts( "" );
  1817. X
  1818. X    nit_loop( s, nit_input );        /* never returns */
  1819. X} /* main */
  1820. X
  1821. X/****************************************************************/
  1822. X
  1823. Xvoid
  1824. Xnit_input( s, nh )
  1825. X    int s;
  1826. X    struct nit_hdr *nh;
  1827. X{
  1828. X    int l;
  1829. X    struct packet *pp;
  1830. X
  1831. X    u_char *p2;
  1832. X    short f, skip;
  1833. X    int len, l2;
  1834. X
  1835. X    l = nh->nh_datalen;
  1836. X    pp = (struct packet *) (((u_char *)nh) + sizeof( struct nit_hdr ));
  1837. X
  1838. X    printf("src ");
  1839. X    petaddr( pp->p_src );
  1840. X    printf(" dest ");
  1841. X    petaddr( pp->p_dst );
  1842. X
  1843. X    p2 = (u_char *) pp->p_data;
  1844. X    skip = CTP_SHORT(p2);
  1845. X
  1846. X    if( skip & 1 )
  1847. X    return;                /* skip must not be odd */
  1848. X
  1849. X    p2 += skip + 2;            /* point to data (skip skip!) */
  1850. X    len = l - 14 - skip - 2;        /* length of data */
  1851. X
  1852. X    printf(" skip %d.\n", skip );
  1853. X    for( ; ; ) {
  1854. X    if( len < 2 )
  1855. X        return;
  1856. X
  1857. X    f = CTP_SHORT( p2 );        /* get function */
  1858. X    p2 += 2;            /* advance past function */
  1859. X    len -= 2;            /* account for function length */
  1860. X    switch( f ) {
  1861. X    case CTP_REP:            /* reply */
  1862. X        printf(" REPLY data: ");
  1863. X        goto break_for;
  1864. X        break;
  1865. X
  1866. X    case CTP_FWD:            /* forward */
  1867. X        if( len < 6 ) {
  1868. X        printf("Too little data for FORWARD packet\n");
  1869. X        return;
  1870. X        }
  1871. X        printf(" FORWARD to: ");
  1872. X        petaddr( p2 );        /* print ether addr */
  1873. X        puts("");
  1874. X        p2 += 6;            /* advance data */
  1875. X        len -=6;            /* account for len */
  1876. X        break;
  1877. X
  1878. X    default:
  1879. X        printf(" fncn %d. data: ", f );
  1880. X        goto break_for;
  1881. X    }
  1882. X    }
  1883. X break_for: ;
  1884. X    l2 = len;
  1885. X    if( l2 > 32 )
  1886. X    l2 = 32;
  1887. X    pbytes( p2, l2 );
  1888. X    if( len > 32 )
  1889. X    printf("...");
  1890. X    puts("");
  1891. X
  1892. X
  1893. X    if( count > 0 )
  1894. X    if( --count == 0 )
  1895. X        exit( 0 );
  1896. X
  1897. X}
  1898. X
  1899. Xpbytes( p, c )
  1900. X    u_char *p;
  1901. X    int c;
  1902. X{
  1903. X    while( c-- > 0 )
  1904. X    printf("%02X", *p++ & 0xff );
  1905. X}
  1906. END_OF_show.c
  1907. if test 3211 -ne `wc -c <show.c`; then
  1908.     echo shar: \"show.c\" unpacked with wrong size!
  1909. fi
  1910. # end of overwriting check
  1911. fi
  1912. if test -f tab.c -a "${1}" != "-c" ; then 
  1913.   echo shar: Will not over-write existing file \"tab.c\"
  1914. else
  1915. echo shar: Extracting \"tab.c\" \(3498 characters\)
  1916. sed "s/^X//" >tab.c <<'END_OF_tab.c'
  1917. X/*
  1918. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  1919. X * All Rights Reserved
  1920. X *
  1921. X * Permission is granted to any individual or institution to use, copy,
  1922. X * or redistribute this software so long as it is not sold for profit,
  1923. X * provided that this notice and the original copyright notices are
  1924. X * retained.  Boston University makes no representations about the
  1925. X * suitability of this software for any purpose.  It is provided "as is"
  1926. X * without express or implied warranty.
  1927. X */
  1928. X# include <stdio.h>
  1929. X# include <ctype.h>
  1930. X# include "packet.h"
  1931. X
  1932. Xstruct hent {
  1933. X    union {
  1934. X    EA hd_ea;
  1935. X    short hd_type;
  1936. X    } h_data;
  1937. X    int h_cnt;
  1938. X    int h_inuse;
  1939. X};
  1940. X# define h_ea h_data.hd_ea
  1941. X# define h_type h_data.hd_type
  1942. X
  1943. X# define HSIZE 1001
  1944. Xstruct hent srchash[ HSIZE ];
  1945. Xstruct hent dsthash[ HSIZE ];
  1946. Xstruct hent typehash[ HSIZE ];
  1947. Xint length[ 1520 ];
  1948. X
  1949. Xint count = 0;
  1950. Xint pc;
  1951. X
  1952. Xmain() {
  1953. X    char line[ 4096 ];
  1954. X    register byte *pp;
  1955. X    register char *lp;
  1956. X    register int i;
  1957. X
  1958. X    pc = 0;
  1959. X    pp = packet.p_bytes;
  1960. X    while( gets( line ) ) {
  1961. X    if( line[0] == ' ' || line[0] == '*' || line[0] == '\0' ) {
  1962. X        if( pc > 0 )
  1963. X        process();
  1964. X        pp = packet.p_bytes;
  1965. X        pc = 0;
  1966. X        continue;
  1967. X    }
  1968. X
  1969. X    for( lp = line; *lp; lp++ ) {
  1970. X        if( isspace( *lp ) )
  1971. X        continue;
  1972. X        else if( isxdigit( *lp ) && isxdigit( lp[1] ) ) {
  1973. X        *pp++ = xval( *lp, lp[1] );
  1974. X        lp++;
  1975. X        pc++;
  1976. X        }
  1977. X        else
  1978. X        fprintf( stderr, "you lose: %s\n", lp );
  1979. X    }
  1980. X    }
  1981. X    if( pc > 0 )
  1982. X    process();
  1983. X    dump_ht_ea( "src", srchash, HSIZE );
  1984. X    dump_ht_ea( "dst", dsthash, HSIZE );
  1985. X    dump_ht_short( "type", typehash, HSIZE );
  1986. X
  1987. X    for( i = 0; i < 1520; i++ )
  1988. X    if( length[i] > 0 )
  1989. X        printf("%4d %4d\n", i, length[i] );
  1990. X}
  1991. X
  1992. Xprocess() {
  1993. X    register struct etherpacket *e = (struct etherpacket *) &packet;
  1994. X    u_short type;
  1995. X
  1996. X    count++;
  1997. X    type = packet.p_ether.e_type;
  1998. X/**
  1999. X    terpri();
  2000. X    printf("esrc: ");
  2001. X    petaddr( e->e_src );
  2002. X    putchar(' ');
  2003. X    putchar('/');
  2004. X    putchar(' ');
  2005. X    printf("edst: ");
  2006. X    petaddr( e->e_dst );
  2007. X    terpri();
  2008. X    printf("type=%02X-%02X len=%d\n",
  2009. X       (type >> 8) & 255,
  2010. X       type & 255,
  2011. X       pc );
  2012. X**/
  2013. X
  2014. X    ent_ea( srchash, e->e_src, HSIZE );
  2015. X    ent_ea( dsthash, e->e_dst, HSIZE );
  2016. X
  2017. X    ent_short( typehash, type, HSIZE );
  2018. X    length[ pc ]++;
  2019. X}
  2020. X
  2021. Xhash( p )
  2022. X    register unsigned char *p;
  2023. X{
  2024. X    register h, h2, l;
  2025. X    l = 3;
  2026. X    h = 0;
  2027. X    while( l-- )
  2028. X    h = (h<<8) | *p++;
  2029. X
  2030. X    l = 3;
  2031. X    h2 = 0;
  2032. X    while( l-- )
  2033. X    h2 = (h2<<8) | *p++;
  2034. X
  2035. X    return( h ^ h2 );
  2036. X}
  2037. X
  2038. Xent_ea( ht, ea, s )
  2039. X    struct hent *ht;
  2040. X    EA ea;
  2041. X{
  2042. X    int h;
  2043. X
  2044. X    h = hash( ea ) % s;
  2045. X
  2046. X    while( ht[ h ].h_inuse && bcmp( ht[h].h_ea, ea, 6) != 0 )
  2047. X    h = (h + 101) % s;
  2048. X
  2049. X    if( !ht[h].h_inuse ) {
  2050. X    bcopy( ea, ht[h].h_ea, 6 );
  2051. X    ht[h].h_inuse = 1;
  2052. X    }
  2053. X
  2054. X    ht[h].h_cnt++;
  2055. X}
  2056. X
  2057. Xent_short( ht, t, s )
  2058. X    struct hent *ht;
  2059. X    unsigned short t;
  2060. X{
  2061. X    int h;
  2062. X
  2063. X    h = t % s;
  2064. X
  2065. X    while( ht[ h ].h_inuse && ht[h].h_type != t )
  2066. X    h = (h + 101) % s;
  2067. X
  2068. X    if( !ht[h].h_inuse ) {
  2069. X    ht[h].h_type = t;
  2070. X    ht[h].h_inuse = 1;
  2071. X    }
  2072. X
  2073. X    ht[h].h_cnt++;
  2074. X}
  2075. X
  2076. Xdump_ht_ea( n, h, s )
  2077. X    char *n;
  2078. X    struct hent *h;
  2079. X{
  2080. X    register int i;
  2081. X    puts( n );
  2082. X    for( i = 0; i < s; i++, h++ )
  2083. X    if( h->h_inuse ) {
  2084. X        printf(" %5d ", h->h_cnt );
  2085. X        petaddrm( h->h_ea );
  2086. X        terpri();
  2087. X    }
  2088. X}
  2089. X
  2090. Xdump_ht_short( n, h, s )
  2091. X    char *n;
  2092. X    struct hent *h;
  2093. X    int s;
  2094. X{
  2095. X    register int i;
  2096. X
  2097. X    puts( n );
  2098. X    for( i = 0; i < s; i++, h++ )
  2099. X    if( h->h_inuse ) {
  2100. X        printf("%02X-%02X %d\n",
  2101. X           (h->h_type >> 8 ) & 255,
  2102. X           (h->h_type) & 255,
  2103. X           h->h_cnt );
  2104. X    }
  2105. X}
  2106. X
  2107. END_OF_tab.c
  2108. if test 3498 -ne `wc -c <tab.c`; then
  2109.     echo shar: \"tab.c\" unpacked with wrong size!
  2110. fi
  2111. # end of overwriting check
  2112. fi
  2113. if test -f terpri.c -a "${1}" != "-c" ; then 
  2114.   echo shar: Will not over-write existing file \"terpri.c\"
  2115. else
  2116. echo shar: Extracting \"terpri.c\" \(554 characters\)
  2117. sed "s/^X//" >terpri.c <<'END_OF_terpri.c'
  2118. X/*
  2119. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  2120. X * All Rights Reserved
  2121. X *
  2122. X * Permission is granted to any individual or institution to use, copy,
  2123. X * or redistribute this software so long as it is not sold for profit,
  2124. X * provided that this notice and the original copyright notices are
  2125. X * retained.  Boston University makes no representations about the
  2126. X * suitability of this software for any purpose.  It is provided "as is"
  2127. X * without express or implied warranty.
  2128. X */
  2129. X# include <stdio.h>
  2130. X
  2131. Xterpri() {
  2132. X    putchar('\n');
  2133. X}
  2134. X
  2135. END_OF_terpri.c
  2136. if test 554 -ne `wc -c <terpri.c`; then
  2137.     echo shar: \"terpri.c\" unpacked with wrong size!
  2138. fi
  2139. # end of overwriting check
  2140. fi
  2141. if test -f test-htoea.c -a "${1}" != "-c" ; then 
  2142.   echo shar: Will not over-write existing file \"test-htoea.c\"
  2143. else
  2144. echo shar: Extracting \"test-htoea.c\" \(844 characters\)
  2145. sed "s/^X//" >test-htoea.c <<'END_OF_test-htoea.c'
  2146. X/*
  2147. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  2148. X * All Rights Reserved
  2149. X *
  2150. X * Permission is granted to any individual or institution to use, copy,
  2151. X * or redistribute this software so long as it is not sold for profit,
  2152. X * provided that this notice and the original copyright notices are
  2153. X * retained.  Boston University makes no representations about the
  2154. X * suitability of this software for any purpose.  It is provided "as is"
  2155. X * without express or implied warranty.
  2156. X */
  2157. Xmain( argc, argv )
  2158. X    int argc;
  2159. X    char *argv[];
  2160. X{
  2161. X    char ea[ 6 ];
  2162. X
  2163. X    argc--;
  2164. X    argv++;
  2165. X
  2166. X    if( argc < 1 )
  2167. X    puts("Usage: htoea {<name> | BCAST | <eaddr> | <ipaddr>}");
  2168. X
  2169. X    while( argc-- > 0 ) {
  2170. X    printf("%s: ", argv[0] );
  2171. X    if( htoea( argv[0], ea ) ) {
  2172. X        petaddr( ea );
  2173. X        terpri();
  2174. X    }
  2175. X    else
  2176. X        puts("failed");
  2177. X
  2178. X    argv++;
  2179. X    }
  2180. X}
  2181. END_OF_test-htoea.c
  2182. if test 844 -ne `wc -c <test-htoea.c`; then
  2183.     echo shar: \"test-htoea.c\" unpacked with wrong size!
  2184. fi
  2185. # end of overwriting check
  2186. fi
  2187. if test -f xval.c -a "${1}" != "-c" ; then 
  2188.   echo shar: Will not over-write existing file \"xval.c\"
  2189. else
  2190. echo shar: Extracting \"xval.c\" \(784 characters\)
  2191. sed "s/^X//" >xval.c <<'END_OF_xval.c'
  2192. X/*
  2193. X * Copyright (c) 1988 Philip L. Budne and The Trustees of Boston University
  2194. X * All Rights Reserved
  2195. X *
  2196. X * Permission is granted to any individual or institution to use, copy,
  2197. X * or redistribute this software so long as it is not sold for profit,
  2198. X * provided that this notice and the original copyright notices are
  2199. X * retained.  Boston University makes no representations about the
  2200. X * suitability of this software for any purpose.  It is provided "as is"
  2201. X * without express or implied warranty.
  2202. X */
  2203. X# include <ctype.h>
  2204. X
  2205. Xxval( c1, c2 )
  2206. Xchar c1, c2;
  2207. X{
  2208. X    int i;
  2209. X    i = (xnybble( c1 ) << 4) + xnybble( c2 );
  2210. X    return( i );
  2211. X}
  2212. X
  2213. Xxnybble( c )
  2214. Xchar c;
  2215. X{
  2216. X    if( isdigit( c ) )
  2217. X    return( c - '0' );
  2218. X    else if( isupper( c ) )
  2219. X    return( c - 'A' + 10 );
  2220. X    else
  2221. X    return( c - 'a' + 10 );
  2222. X}
  2223. X
  2224. END_OF_xval.c
  2225. if test 784 -ne `wc -c <xval.c`; then
  2226.     echo shar: \"xval.c\" unpacked with wrong size!
  2227. fi
  2228. # end of overwriting check
  2229. fi
  2230. echo shar: End of archive 1 \(of 2\).
  2231. cp /dev/null ark1isdone
  2232. MISSING=""
  2233. for I in 1 2 ; do
  2234.     if test ! -f ark${I}isdone ; then
  2235.     MISSING="${MISSING} ${I}"
  2236.     fi
  2237. done
  2238. if test "${MISSING}" = "" ; then
  2239.     echo You have unpacked both archives.
  2240.     rm -f ark[1-9]isdone
  2241. else
  2242.     echo You still need to unpack the following archives:
  2243.     echo "        " ${MISSING}
  2244. fi
  2245. ##  End of shell archive.
  2246. exit 0
  2247.